FROM ubuntu:jammy AS base

# https://askubuntu.com/questions/909277/avoiding-user-interaction-with-tzdata-when-installing-certbot-in-a-docker-contai
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y --no-install-recommends --no-install-suggests \
    ca-certificates \
    curl \
    cmake \
    gnupg \
    make \
    perl \
    python3 \
    python3-pip \
    clang \
    clang-format

ENV CC=clang
ENV CXX=clang++

WORKDIR /src

FROM base as build
RUN pip --no-cache-dir install conan
RUN conan profile detect --force
COPY ./foxglove-websocket /src/foxglove-websocket/
ARG CPPSTD=17
ARG ASIO=standalone
RUN conan create foxglove-websocket -s compiler.cppstd=$CPPSTD --build=missing -o foxglove-websocket*:asio=$ASIO

FROM build as build_examples
COPY --from=build /root/.conan2 /root/.conan2
COPY ./examples /src/examples
RUN conan build examples --output-folder examples/ -s compiler.cppstd=$CPPSTD --build=missing

FROM build_examples AS example_server_protobuf
CMD ["examples/build/Release/example_server_protobuf"]

FROM build_examples AS example_server_flatbuffers
CMD ["examples/build/Release/example_server_flatbuffers", "/src/examples/autogenerated_flatbuffers/SceneUpdate.bfbs"]

FROM build_examples AS example_server_json
CMD ["examples/build/Release/example_server_json"]

FROM build_examples AS example_server_perf_test
CMD ["examples/build/Release/example_server_perf_test"]

FROM build_examples AS example_client_perf_test
CMD ["examples/build/Release/example_client_perf_test"]
